package mail.gui;

import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableModel;

import mail.MultiEmail;
import mail.bean.EmailBean;

public class ListPanel extends JPanel {
	private JTable table;
	private ListTableModel model = null; 
	private MultiEmail top = null;
	public ListPanel(MultiEmail multiEmail) {
		super();
		setPreferredSize(new Dimension(580, 200));
		top=multiEmail;

		final JScrollPane scrollPane = new JScrollPane();
		scrollPane.setPreferredSize(new Dimension(570, 190));
		add(scrollPane);

		table = new JTable();
		model = new ListTableModel();
		table.setModel(model);
		table.addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        super.mouseClicked(e);
        if(MouseEvent.BUTTON1 == e.getButton()) {
          EmailBean bean = model.getEmailList().get(table.getSelectedRow());
          top.getMailPanel().showMail(bean);
        }
      }
    });
		scrollPane.setViewportView(table);
	
	}
  public ListTableModel getModel() {
    return model;
  }
  public void setModel(ListTableModel model) {
    this.model = model;
  }
  public JTable getTable() {
    return table;
  }
  public void setTable(JTable table) {
    this.table = table;
  }

}
